package com.chixing.service.impl;

import com.chixing.mapper.ShopMapper;
import com.chixing.pojo.Shop;
import com.chixing.pojo.ShopExample;
import com.chixing.service.ShopService;
import com.chixing.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ShopServiceImpl implements ShopService {


    @Override
    public List<Shop> getShopByMoreCondition(String shopBranchName, Float minPersonConsumePrice, Float maxPersonConsumePrice,
                                             String shopAddrProvince, String shopAddrCity, Float shopScore) {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        ShopMapper shopMapper = sqlSession.getMapper(ShopMapper.class);
        ShopExample example = new ShopExample();
        ShopExample.Criteria criteria = example.createCriteria();

        if (shopBranchName != null)
            criteria.andShopNameLike("%" + shopBranchName +"%");
        if (minPersonConsumePrice != null)
            criteria.andShopPersonConsumeGreaterThanOrEqualTo(minPersonConsumePrice);
        if (maxPersonConsumePrice != null)
            criteria.andShopPersonConsumeLessThanOrEqualTo(maxPersonConsumePrice);
        if (shopAddrProvince != null)
            criteria.andShopAddrAreaEqualTo(shopAddrProvince);
        if (shopAddrCity != null)
            criteria.andShopAddrCityEqualTo(shopAddrCity);
        if (shopScore != null)
            criteria.andShopScoreEqualTo(shopScore);

        example.setOrderByClause("shop_score desc"); // 按照评分

        return shopMapper.selectByExample(example);
    }

    @Override
    public List<Shop> getDishByShop() {
        return null;
    }
}
